package de.tum.wi.som.rcpsp.entities;

/**
 * This entity foocuses on assigning an activity the needed ressources at a given  
 * time period.  The workContent Resources provides the conditions for the Assignment. 
 *
 */
public class ResourceAssignment implements Comparable<ResourceAssignment>{

	private int resourceUnits;
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((Activity == null) ? 0 : Activity.hashCode());
		result = prime * result + resourceUnits;
		result = prime * result
				+ ((timePeriod == null) ? 0 : timePeriod.hashCode());
		result = prime
				* result
				+ ((workContentResource == null) ? 0 : workContentResource
						.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ResourceAssignment other = (ResourceAssignment) obj;
		if (Activity == null) {
			if (other.Activity != null)
				return false;
		} else if (!Activity.equals(other.Activity))
			return false;
		if (resourceUnits != other.resourceUnits)
			return false;
		if (timePeriod == null) {
			if (other.timePeriod != null)
				return false;
		} else if (!timePeriod.equals(other.timePeriod))
			return false;
		if (workContentResource == null) {
			if (other.workContentResource != null)
				return false;
		} else if (!workContentResource.equals(other.workContentResource))
			return false;
		return true;
	}

	private Activity Activity;
	private TimePeriod timePeriod;
	
	public ResourceAssignment(int resourceUnits,
			de.tum.wi.som.rcpsp.entities.Activity activity,
			TimePeriod timePeriod, WorkContentResource workContentResource) {
		super();
		this.resourceUnits = resourceUnits;
		Activity = activity;
		this.timePeriod = timePeriod;
		this.workContentResource = workContentResource;
	}

	public TimePeriod getTimePeriod() {
		return timePeriod;
	}

	public void setTimePeriod(TimePeriod timePeriod) {
		this.timePeriod = timePeriod;
	}

	private WorkContentResource workContentResource;
	

	public ResourceAssignment(int resourceUnits) {
		super();
		this.resourceUnits = resourceUnits;
	}



	public int getResourceUnits() {
		return resourceUnits;
	}

	public void setResourceUnits(int resourceUnits) {
		this.resourceUnits = resourceUnits;
	}

	public Activity getActivity() {
		return Activity;
	}

	public void setActivity(Activity activity) {
		Activity = activity;
	}

	public WorkContentResource getWorkContentResource() {
		return workContentResource;
	}

	public void setWorkContentResource(WorkContentResource workContentResource) {
		this.workContentResource = workContentResource;
	}

	@Override
	public int compareTo(ResourceAssignment o) {
		if(this.timePeriod.getTime()==o.timePeriod.getTime()){
			return this.getActivity().getName().compareTo(o.getActivity().getName());			
		}
		else if(this.timePeriod.getTime()<o.timePeriod.getTime()){
			return 1;
		}
		else{
			return -1;
		}
	}
	
	@Override
	public String toString() {
		return "Aktivitaet " + getActivity() + ": " + getResourceUnits() + " Einheiten.";
	}
	
	
}
